package deck;

import java.io.Serializable;

public class Card implements Comparable<Card>, Serializable{
	private Suit suit;
	private Value value;
	private boolean visible, playable, selected;
	
	public Card() {
		visible = false;
		selected = false;
		playable = true;
	}
	
	public Card(Suit suit, Value value) {
		this.suit = suit;
		this.value = value;
		this.visible = false;
		this.playable = true;
		this.selected = false;
	}
	
	public void setCard(Card card){
		visible = card != null;
		if(visible){
			this.setSuit(card.suit);
			this.setValue(card.value);
		}
	}
	
	public boolean isVisible(){
		return visible;
	}
	
	public boolean isPlayable(){
		return playable;
	}
	
	public boolean isSelected(){
		return selected;
	}
	
	public void setSelected(boolean selected){
		this.selected = selected;
	}
	
	public void setPlayable(boolean playable){
		this.playable = playable; 
	}
	
	public void setSuit(Suit suit) {
		this.suit = suit;
	}
	
	public Suit getSuit() {
		return suit;
	}
	
	public void setValue(Value value) {
		this.value = value;
	}
	
	public Value getValue() {
		return value;
	}
	
	public String toString() {
		return value.toString() + " of " + suit.toString();
	}

	@Override
	public int compareTo(Card arg0) {
		return value.compareTo(arg0.value);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((suit == null) ? 0 : suit.hashCode());
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Card))
			return false;
		Card other = (Card) obj;
		if (suit != other.suit)
			return false;
		if (value != other.value)
			return false;
		return true;
	}
}
